/*! \file 
	\brief Holds declarations for the interprocess communication sub-system. */

#ifndef _IPC_H_
#define	_IPC_H_

#include "macros.h"

#define MAX_NUMBER_OF_PORTS 16
#define MAX_NUMBER_OF_WAITING_MESSAGES 8

struct message {
	char* data; // The type of the pointer should have a size so it can be copied.
	int size;
	enum {
		string, binary
	} type;
	int dest_port;
	int src_port;
};

struct msg_queue {
	struct message messages[MAX_NUMBER_OF_WAITING_MESSAGES];
	int head;
	int tail;
};

struct port {
	int port_id;
	int owner;
	void (*handler)(void);		// Set to 0 if no handler is to be called (used with polling)
	struct msg_queue msg_queue;
};

extern struct port port_table[MAX_NUMBER_OF_PORTS];

//int message_enqueue(struct message m);
//struct message message_dequeue();

void initialize_message_passing(void);

int kcreate_mailbox(void (*handler)(void), int port_id);

int kdelete_mailbox(int port_id);

int ksend_msg(struct message* m);

int kretrieve_msg(struct message* m, int port_id);


#endif	/* IPC_H */



